home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / NextDeveloper / Examples / AppKit / CalculatorLab / MinusPanel.m < prev    next >
Text File  |  1990-10-29  |  1KB  |  39 lines

  1. //    MinusPanel.m
  2. //    
  3. //    You may freely copy, distribute and reuse the code in this example.
  4. //    NeXT disclaims any warranty of any kind, expressed or implied, as to
  5. //    its fitness for any particular use.
  6. //
  7.  
  8. #import "MinusPanel.h"
  9.  
  10. @implementation MinusPanel
  11.  
  12. // When the user presses the minus sign on the keypad, the resulting character
  13. // is number 45 from the Symbol character set, not a minus sign from the ASCII
  14. // character set (which you would get by pressing the key to the right of the 
  15. // zero key).  The Panel class ignores commandKeys from all sets except the 
  16. // ASCII set, but we want the user to be able to depress the minus key on the
  17. // keypad and have it act like the real minus key.  We can get around this
  18. // problem by checking for this special minus sign and converting it into an
  19. // ASCII minus sign before it reaches the regular commandKey: method
  20. - (BOOL)commandKey:(NXEvent *)theEvent
  21. {
  22.     NXEvent localEvent;
  23.     BOOL    symbolSet, minusSign;
  24.     
  25.     symbolSet = theEvent->data.key.charSet == NX_SYMBOLSET;
  26.     minusSign = theEvent->data.key.charCode == 45;
  27.  
  28.     if (symbolSet && minusSign) {  /* check for minus */
  29.     localEvent = *theEvent;
  30.     localEvent.data.key.charSet = NX_ASCIISET;
  31.     localEvent.data.key.charCode = '-';
  32.     return [super commandKey:&localEvent];
  33.     } else {
  34.         return [super commandKey:theEvent];
  35.     }
  36. }
  37.  
  38. @end
  39.